﻿
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="widgets-list" lay-filter="widgets-list"></table>
            <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>@T("Admin.ContentManagement.Widgets.Configure")</a>
            </script>
        </div>
    </div>
</div>

<script>
    layui.use(['index', 'table'], function () {
        var index = layer.load(2, { shade: false });
            var table = layui.table
                , form = layui.form;
        //分类管理
        table.render({
            elem: '#widgets-list'
            , method: 'post'
            , url: '@Html.Raw(Url.Action("List"))' //模拟接口
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'FriendlyName', title: '@T("Admin.ContentManagement.Widgets.Fields.FriendlyName")', minWidth: 100 }
                , { field: 'SystemName', title: '@T("Admin.ContentManagement.Widgets.Fields.SystemName")', width: 100 }
                , { field: 'DisplayOrder', title: '@T("Admin.ContentManagement.Widgets.Fields.DisplayOrder")', width: 100, align: 'center' }
                , { field: 'IsActive', title: '@T("Admin.ContentManagement.Widgets.Fields.IsActive")', templet: '#activeTpl', width: 100, align: 'center' }
                , { title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar' }
            ]]
            , text: '对不起，加载出现异常！'
            , id: 'testReload'
            , page: true
            , done: function () {
                layer.close(index);
            }
            });
        //监听工具条
        table.on('tool(widgets-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑'
                    , type: 2
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['100%', '100%']
                    , content: '@Url.Action("ConfigureWidget")systemName=' + data.SystemName
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
         });

        //监听锁定操作
         form.on('switch(activeTpl)', function (obj) {
            var check = obj.elem.checked;
            $.post('@Url.Action("WidgetUpdate")', { Id: this.value, checked: check });
         })


        var $ = layui.$, active = { }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

